package com.onepice.mlp.core.serviceImpl;

import com.onepice.mlp.core.service.RoleService;
import com.onepice.mlp.data.dao.RoleDao;
import com.onepice.mlp.data.entity.Role;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/07/11 23:25:03
 */
@Service
@AllArgsConstructor
@Transactional
public class RoleServiceImpl implements RoleService {
    private RoleDao roleDao;

    @Override
    public List<Role> getAll() {
        return roleDao.findAll();
    }

    @Override
    public Role getById(Integer id) {
        Optional<Role> role = roleDao.findById(id);
        return role.get();
    }

    @Override
    public void insert(Role role) {
        roleDao.save(role);
    }

    @Override
    public void update(Role role) {
        roleDao.save(role);
    }

    @Override
    public void deleteById(Integer id) {
        roleDao.deleteById(id);
    }
}
